package com.cloud.pole.rpc;

import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.ace.cache.api.CacheAPI;
import com.cloud.pole.common.constant.CacheConstant;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.msg.model.entity.SmsSendHis;
import com.cloud.pole.msg.service.SmsSendHisService;
import com.cloud.pole.msg.service.SmsSendService;
import com.cloud.pole.msg.service.VerifyCodeService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("api/verifyCode")
public class VerifyCodeRest {
	
	@Autowired
    private VerifyCodeService verifyCodeService;
	
	/**
	 * 检查验证短信验证码
	 * @param mobile
	 * @param verifyCode
	 * @param templateKey
	 * @return
	 */
	@RequestMapping(value = "/checkVerifyCode")
    @ResponseBody
    public ApiRestResponse<Boolean> checkVerifyCode(
    		@RequestParam(defaultValue = "") String mobileArea,
    		@RequestParam(defaultValue = "") String mobile,
    		@RequestParam(defaultValue = "") String templateKey,
    		@RequestParam(defaultValue = "") String verifyCode){
		try {
			ParamException.err(StringUtils.isBlank(mobileArea), "mobileArea不能为空");
			ParamException.err(StringUtils.isBlank(mobile), "mobile不能为空");
			ParamException.err(StringUtils.isBlank(templateKey), "templateKey不能为空");
			ParamException.err(StringUtils.isBlank(verifyCode), "verifyCode不能为空");
			Boolean result = verifyCodeService.checkVerifyCode(mobileArea, mobile, templateKey, verifyCode);
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, result);
		} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
}
